<?php

namespace JsonLowCode\UI;

use JsonLowCode\Schema;
use JsonLowCode\UI;
use JsonLowCode\Traits\Events\HasRouterEvent;
use JsonLowCode\Traits\Props\HasBordered;
use JsonLowCode\Traits\Props\HasDisabled;
use JsonLowCode\Traits\Props\HasLoading;
use JsonLowCode\Traits\Props\HasRound;
use JsonLowCode\Traits\Props\HasTinySize;
use JsonLowCode\Traits\Props\HasTag;
use JsonLowCode\Traits\Props\HasType;
use JsonLowCode\Traits\Slots\HasSlotIcon;

/**
 * 按钮组件 NButton
 * @method static Button make(mixed $children = null, string|Icon $icon = null, string $iconPlacement = "left") Button 按钮组件
 */
class Button extends Schema
{

    protected string $componentName = "NButton";

    use HasTag, HasTinySize, HasType, HasLoading, HasDisabled, HasBordered, HasRound;

    use HasSlotIcon;

    use HasRouterEvent;

    /**
     * @param mixed|null $children
     * @param string|Icon|null $icon
     * @param string $iconPlacement
     */
    public function __construct(mixed $children = null, string|Icon $icon = null, string $iconPlacement = "left")
    {
        parent::__construct();
        $this->children($children);
        if ($icon!==null){
            if ($icon instanceof Icon){
                $this->slotIcon($icon);
            }else{
                $this->slotIcon(UI::icon($icon));
            }
            $this->iconPlacement($iconPlacement);
        }
    }

    /**
     * 按钮类型
     * @param string $type 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error'
     * @return $this
     */
    public function type(string $type = 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error'): static
    {
        return $this->prop('type',$type);
    }

    /**
     * 默认按钮类型
     * @return $this
     */
    public function default(): static
    {
        return $this->type('default');
    }

    /**
     * 是否是二级按钮
     * @param bool|string $bool
     * @return $this
     */
    public function secondary(bool $bool = true): static
    {
        return $this->prop('secondary', $bool);
    }

    /**
     * 是否是三级按钮
     * @param bool $bool 否:设置type=tertiary, 是设置tertiary=$bool
     * @return $this
     */
    public function tertiary(bool $bool = false): static
    {
        return $bool?$this->prop('tertiary',true):$this->type('tertiary');
    }

    /**
     * 是否是四级按钮
     * @param bool|string $bool
     * @return $this
     */
    public function quaternary(bool|string $bool = true): static
    {
        return $this->prop('quaternary', $bool);
    }


    /**
     * 按钮是否显示为块级
     * @param bool|string $bool
     * @return $this
     */
    public function block(bool|string $bool = true): static
    {
        return $this->prop('block', $bool);
    }

    /**
     * 按钮是否为圆形
     * @param bool $bool
     * @return $this
     */
    public function circle(bool $bool = true): static
    {
        return $this->prop('circle', $bool);
    }

    /**
     * 设置按钮背景颜色
     * @param string $color
     * @return $this
     */
    public function color(string $color = ''): static
    {
        return $this->prop('color', $color);
    }

    /**
     * 是否为虚线
     * @param bool $bool
     * @return $this
     */
    public function dashed(bool $bool = true): static
    {
        return $this->prop('dashed', $bool);
    }


    /**
     * 按钮是否可以被聚焦
     * @param bool $bool
     * @return $this
     */
    public function focusable(bool $bool = true): static
    {
        return $this->prop('focusable', $bool);
    }

    /**
     * 按钮是否透明
     * @param bool $bool
     * @return $this
     */
    public function ghost(bool $bool = true): static
    {
        return $this->prop('ghost', $bool);
    }

    /**
     * 是否支持键盘操作
     * @param bool $bool
     * @return $this
     */
    public function keyboard(bool $bool = true): static
    {
        return $this->prop('keyboard', $bool);
    }


    /**
     * 按钮是否加粗
     * @param bool $bool
     * @return $this
     */
    public function strong(bool $bool = true): static
    {
        return $this->prop('strong', $bool);
    }

    /**
     * 是否显示为文本按钮
     * @param bool $bool
     * @return $this
     */
    public function text(bool $bool = true): static
    {
        return $this->prop('text', $bool);
    }

    /**
     * 按钮文字颜色
     * @param string $color
     *
     * @return $this
     */
    public function textColor(string $color = ''): static
    {
        return $this->prop('textColor', $color);
    }

    /**
     * 按钮中图标的位置
     * @param string $iconPlacement 'left' | 'right'
     * @return $this
     */
    public function iconPlacement(string $iconPlacement = 'left' | 'right'): static
    {
        return $this->prop('iconPlacement', $iconPlacement);
    }

    /**
     * 按钮的 DOM 的 type 属性
     * @param string $attrType 'button' | 'submit' | 'reset'
     * @return $this
     */
    public function attrType(string $attrType = 'button' | 'submit' | 'reset'): static
    {
        return $this->prop('attrType', $attrType);
    }

}
